<?php

declare(strict_types=1);

use App\Migration\MigrationInterface;
use PDO;

return new class implements MigrationInterface {
    public function getId(): string
    {
        return '20250208000100_create_webhooks_table';
    }

    public function up(PDO $pdo): void
    {
        $pdo->exec(
            <<<'SQL'
            CREATE TABLE IF NOT EXISTS webhooks (
                id SERIAL PRIMARY KEY,
                token VARCHAR(36) NOT NULL UNIQUE,
                label VARCHAR(255) DEFAULT NULL,
                response_status SMALLINT NOT NULL DEFAULT 200,
                response_content_type VARCHAR(255) NOT NULL DEFAULT 'application/json',
                response_headers TEXT NOT NULL DEFAULT '',
                response_body TEXT NOT NULL DEFAULT '',
                created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
                last_accessed_at TIMESTAMPTZ DEFAULT NULL
            )
            SQL,
        );
    }

    public function down(PDO $pdo): void
    {
        $pdo->exec('DROP TABLE IF EXISTS webhooks');
    }
};
